using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;

namespace VisualPureBasicIDE.FormDesigner.Implementations
{
    public class TypeDescriptorFilterService : ITypeDescriptorFilterService
    {
        private readonly IDesignerHost _host;

        public TypeDescriptorFilterService(IDesignerHost host)
        {
            _host = host;
        }

        #region ITypeDescriptorFilterService Members

        public bool FilterAttributes(IComponent component, IDictionary attributes)
        {
            var designer = _host.GetDesigner(component);
            if (designer is IDesignerFilter)
            {
                var designerFilter = designer as IDesignerFilter;

                designerFilter.PreFilterAttributes(attributes);
                designerFilter.PostFilterAttributes(attributes);

                return true;
            }

            return false;
        }

        public bool FilterEvents(IComponent component, IDictionary events)
        {
            var designer = _host.GetDesigner(component);
            if (designer is IDesignerFilter)
            {
                var designerFilter = designer as IDesignerFilter;

                designerFilter.PreFilterEvents(events);
                designerFilter.PostFilterEvents(events);

                return true;
            }

            return false;
        }

        public bool FilterProperties(IComponent component, IDictionary properties)
        {
            var designer = _host.GetDesigner(component);
            if (designer is IDesignerFilter)
            {
                var designerFilter = designer as IDesignerFilter;

                designerFilter.PreFilterProperties(properties);
                designerFilter.PostFilterProperties(properties);

                return true;
            }

            return false;
        }

        #endregion
    }
}